#!/usr/bin/env python
# encoding: utf-8
"""
icap-allow-304.py

Created by Thomas Mangin on 2011-11-29.
Copyright (c) 2011-2013  Exa Networks. All rights reserved.
"""

import sys

try:
	while True:
		line = sys.stdin.readline()
		method,uri,version = line.rstrip().split()
		if method != 'REQMOD':
			sys.stderr.write('ICAP METHOD not supported %s\n' % method)
			sys.stderr.flush()
		if version != 'ICAP/1.0':
			sys.stderr.write('ICAP version not supported %s\n' % version)
			sys.stderr.flush()

		# consume the message
		empty = 2
		while empty:
			line = sys.stdin.readline()
			if not line.rstrip():
				empty -= 1

		sys.stdout.write("ICAP/1.0 304 OK\n\n")
		sys.stdout.flush()
except KeyboardInterrupt, e:
	sys.stderr.write('^C keyboard interrupt. exiting.\n')
	sys.stderr.flush()
except Exception, e:
	sys.stderr.write('CHILD FAILED %s\n' % str(e))
	sys.stderr.flush()
